local console = ac.console

local models = {
    ['积分'] = [[core\反馈\jfbz.mdl]],
    ['金币'] = [[core\反馈\jbbz.mdl]],
    ['木材'] = [[core\反馈\mtbz.mdl]],
    ['杀敌'] = [[core\反馈\sdbz.mdl]],
    ['失败'] = [[core\反馈\sjsb.mdl]],
    ['成功'] = [[core\反馈\cg.mdl]],
    ['新的'] = [[core\反馈\new.mdl]],
    ['吞噬'] = [[core\反馈\ts.mdl]],
    
    ['兑换成功'] = [[core\反馈\dhcg.mdl]],
    ['概率提升'] = [[core\反馈\glts.mdl]],
    ['刷新'] = [[core\反馈\shuaxin.mdl]],
}

local uis = {}
for a=1,10 do
    local ui = class.panel.create('',500,500,1,1)
    ui:set_level(9)
    ui.animation_icon = ui:add_panel('')
    ui.model = ui:add_model('')
    uis[a] = ui
end

local index = 0
local function get_ui()
    index = index%10 + 1
    return uis[index]
end

local skill_buttons = {}
local slots = {9,10,11,12,5,6,7,8,1,2,3,4}
for a,button in ipairs(console.abilitydetail) do
    local x,y = button:get_real_position()
    local id = slots[a]
    skill_buttons[id] = {x + button.w/2,y + button.h/2,button.w,button.h}
end

local item_buttons = {}
for _,button in ipairs(console.itemdetail) do
    local x,y = button:get_real_position()
    item_buttons[button.slotid] = {x + button.w/2,y + button.h/2,button.w,button.h}
end


local open = false
function show_ui_effect(player,x,y,class,w,h)
    local path = models[class]
    if player:is_self() then
        local ui = get_ui()
        if class=='刷新' then
            local w = w or 64
            local h = h or 64
            ui.animation_path = 'cddone%02d.blp'
            ui.animation_count = 12
            ui.animation_icon:set_control_size(w*1.3,h*1.3)
            ui:set_real_position(x-w*0.65,y-h*0.65)
            ui:play_animation()
            ui.model:hide()
            return
        end
        ui:set_real_position(x+ui.w/2,y-ui.h/2)
        ui.model:hide()
        ui.model:set_model(path)
        ui.model:set_animation_by_index(1)
        ui.model:show()
    end
    if open==false then
        open = true
        ac.wait(0,function()
            open = false
            index = 0
        end)
    end
end

function show_panel_effect(player,panel,class,offset_x,offset_y)
    local offset_x,offset_y = offset_x or 0,offset_y or 0
    local x,y = panel:get_real_position()
    local w,h = panel.w,panel.h
    show_ui_effect(player,x+offset_x+w/2,y+offset_y+h/2,class,w,h)
end

function show_item_tip(player,index,class,offset_x,offset_y)
    local offset_x,offset_y = offset_x or 0,offset_y or 0
    local index = type(index)=='table' and index.slotid or index
    if type(index)~='number' then
        return
    end
    local point = item_buttons[index] or index
    local x,y = point[1],point[2]
    local w,h = point[3],point[4]
    show_ui_effect(player,x+offset_x,y+offset_y,class,w,h)
end

function show_skill_tip(player,index,class,offset_x,offset_y)
    local offset_x,offset_y = offset_x or 0,offset_y or 0
    local index = type(index)=='table' and index.slotid or index
    local point = skill_buttons[index] or index
    local x,y = point[1],point[2]
    local w,h = point[3],point[4]
    show_ui_effect(player,x+offset_x,y+offset_y,class,w,h)
end
